package com.books.mapper.common;

import com.books.model.entity.common.People;
import org.apache.ibatis.annotations.*;


import java.util.Date;
import java.util.List;

/**
 * @Author 饿熊的咆哮
 * @Date 2021/9/28 18:24
 * @Version 1.0
 */
@Mapper
public interface PeopleMapper {
    @Select("select * from people")
    List<People> findAll();

    @Select("select * from people where if_admin=false")
    List<People> findUser();

    @Select("select * from people where people_id=#{peopleId}")
    People findByPeopleId(Integer peopleId);

    @Select("select * from people where id_num=#{idNum}")
    People findByIdNum(String idNum);

    @Select("select * from people where name=#{name}")
    List<People> findByName(String name);

    @Select("select * from people where phone=#{phone}")
    People findByPhone(String phone);

    @Select("select * from people where email=#{email}")
    People findByEmail(String email);

    @Select("select * from people where qq=#{qq}")
    People findByQQ(String qq);

    @Select("select * from people where wx=#{wx}")
    People findByWX(String wx);

    @Insert("insert into people values(null,null,null,#{name},null,null,null,#{phone},#{registrationTime},#{email},null,null,#{vipId},#{ifAdmin},null,#{statusId},#{vipIntegral})")
    void addPeople(People people);

    @Update("update people set head_url=#{people.headUrl},id_num=#{people.idNum},name=#{people.name},sex=#{people.sex},age=#{people.age},birthday=#{people.birthday},email=#{people.email},qq=#{people.qq},wx=#{people.wx},vip_id=#{people.vipId},address=#{people.address},status_id=#{people.statusId} where people_id=#{peopleId}")
    void updatePeople(People people,Integer peopleId);

    @Update("update people set vip_integral=#{vipIntegral},vip_id=#{vipId} where people_id=#{peopleId}")
    void updateVipIntegral(Double vipIntegral,Integer vipId,Integer peopleId);

    @Delete("delete from people where people_id=#{peopleId}")
    void delByPeopleId(Integer peopleId);

    @Update("update people set head_url=#{people.headUrl},id_num=#{people.idNum},name=#{people.name},sex=#{people.sex},age=#{people.age},birthday=#{people.birthday},email=#{people.email},qq=#{people.qq},wx=#{people.wx} where phone=#{phone}")
    int modifyPerson(People people,String phone);

    @Select ("select head_url from people where phone=#{phone}")
    String findHeadUrl(String phone);

    @Select ("select people_id from people where phone=#{phone}")
    Integer findPeopleId(String phone);

    @Update ("update user_login set uName=#{uname} where account=#{account}")
    void modifyUname(String uname,String account);

    @Select ("select birthday from people where phone=#{phone}")
    Date getBirthday(String phone);



}
